package org.particles.domain.field;

import org.particles.domain.ExpFunction;
import org.particles.domain.Particle;
import org.particles.domain.Vector;

/**
 * use this force for gravitation simulation. uses per default strength 10
 * and ExpFunction with factor 10.
 */
public class AttractionForce extends AbstractField {
	
	public AttractionForce(final long fieldMarker) {
		super(fieldMarker);
		setStrength(10);
		setDistanceFunc(new ExpFunction(getStrength()));
	}

	@Override
	public void applyForces(Particle p1, Particle p2) {
		final double distanceToParticle = p1.distanceTo(p2);
		final double factor = getDistanceFunc().calc(distanceToParticle);
		final double forceStrengthForParticle = getStrength() * factor;
		final Vector forceVector = p2.getSpacePlace().subtractFrom(p1.getSpacePlace());
		forceVector.setLength(forceStrengthForParticle);
		p2.getImpulse().add(forceVector);
	}

}
